﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using ChinaSoft.DBUtility;

namespace ChinaSoft.DAL.Common
{
    public class Bind
    {
        public DataSet GetDataSet(string ColumnNames,string tablename,string strwhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select " + ColumnNames+" from "+tablename);
            if (strwhere.Trim() != "")
            {
                strSql.Append(" where " + strwhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }
        /// <summary>
        /// 根据sql查询结果
        /// </summary>
        /// <param name="sqlstr"></param>
        /// <returns></returns>
        public DataSet GetDataSet(string sqlstr)
        {
            return DbHelperOra.Query(sqlstr);
        }
        /// <summary>
        /// 根据条件查询指定的字段的值
        /// 作者：demo
        /// 时间：2012-4-11
        /// </summary>
        /// <param name="Filed">字段名字</param>
        /// <param name="tableName">表名或者试图名字</param>
        /// <param name="sqlstr">条件（条件需要全部自己写，如果需要where，则需要写where）</param>
        /// <returns></returns>
        public object GetFiledContent(string Filed, string tableName, string sqlstr)
        {
            string sql = "select "+Filed+" from "+tableName+" "+sqlstr;
            return DbHelperOra.GetSingle(sql);
        }
        /// <summary>
        /// 根据条件删除指定信息
        /// 作者：demo
        /// 时间：2012-4-11
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="strWhere">条件（不带where）</param>
        /// <returns></returns>
        public bool DeleteWhere(string tableName, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from " + tableName);
            strSql.Append(" where " + strWhere+ "  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string TableName,string KeyName,string CustomerIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from " + TableName);
            strSql.Append(" where " + KeyName + " in (" + CustomerIdlist + ")  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量更新数据
        /// 作者：卢亚东
        /// 时间：2012-3-14
        /// </summary>
        /// <param name="dataFileds">更新的字段</param>
        /// <param name="tableName">表名</param>
        /// <param name="strWhere">条件</param>
        /// <returns></returns>
        public bool UpdateList(string dataFileds, string tableName, string strWhere)
        {
            string sql = "update "+tableName+" set "+dataFileds;
            if (strWhere.Trim() != "")
                sql = sql +" where "+strWhere;
            int rows = DbHelperOra.ExecuteSql(sql);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
